package com.springframework.boot.awesome.annotation.arch.util;

import com.springframework.boot.awesome.annotation.arch.exception.FTPCloseErrorException;
import com.springframework.boot.awesome.annotation.arch.exception.IPErrorException;
import com.springframework.boot.awesome.annotation.arch.exception.PortErrorException;
import com.springframework.boot.awesome.annotation.arch.exception.UserNameOrPasswordErrorException;
import com.springframework.boot.awesome.annotation.arch.entity.FTPConfig;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.TimeoutException;

public class MonitorUtil {
    private static final String FTP = "ftp";
    private static final String SFTP = "sftp";

    public static void monitorFileNameList(long frequency, Method handleFileMethod, Object obj, FTPConfig ftpConfig, long timeout)
            throws IOException, InvocationTargetException, PortErrorException, TimeoutException, InterruptedException,
            IllegalAccessException, FTPCloseErrorException, IPErrorException, UserNameOrPasswordErrorException,
            SftpException, JSchException {
        if(ftpConfig.getProtocal().equals(FTP)){
            FTPUtil.monitorFile(frequency, handleFileMethod, obj,  ftpConfig, timeout);
        }else if(ftpConfig.getProtocal().equals(SFTP)){
            SFTPUtil.monitorFile(frequency, handleFileMethod, obj, ftpConfig, timeout);
        }

    }
}
